import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getQuestionsPage',
    method: 'post',
    data: data
  })
}

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    category: queryParams.category, //试题分类
    theType: queryParams.theType, //题型 1-单选 2-多选 3-判断 4-填空
  }
  return request({
    url: '/getQuestionsList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      categoryId: val.categoryId, //试题分类 id
      categoryVal: val.categoryVal, //试题分类
      theType: val.theType, //题型 1-单选 2-多选 3-判断 4-填空
      subject: val.subject, //题目
      thePic: val.thePic, //
      theVideo: val.theVideo, //
      options: val.options, //选项
      answer: val.answer, //答案
      analysis: val.analysis, //解析
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
    }
  }
  return request({
    url: '/addQuestions',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getQuestionsData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      categoryId: val.categoryId, //试题分类 id
      categoryVal: val.categoryVal, //试题分类
      theType: val.theType, //题型 1-单选 2-多选 3-判断 4-填空
      subject: val.subject, //题目
      thePic: val.thePic, //
      theVideo: val.theVideo, //
      options: val.options, //选项
      answer: val.answer, //答案
      analysis: val.analysis, //解析
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
    }
  }
  return request({
    url: '/updateQuestions',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delQuestions',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleQuestions',
    method: 'post',
    data: data
  })
}

// 下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getQuestionsComboBox',
    method: 'post',
    data: data
  })
}

// 修改启用状态  enable 启用状态  0-未启用 1-已启用
export function getEnable(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableQuestions',
    method: 'post',
    data: data
  })
}